﻿
using System.Collections.Generic;

namespace FrameWorkSong
{
    public static class DictionaryExtention
    {
        /// <summary>
        /// get值
        /// </summary>
        /// <typeparam name="Tkey"></typeparam>
        /// <typeparam name="Tvalue"></typeparam>
        /// <param name="dict"></param>
        /// <param name="tkey"></param>
        /// <returns></returns>
        public static Tvalue TryGat<Tkey, Tvalue>(this Dictionary<Tkey, Tvalue> dict, Tkey tkey)
        {
            Tvalue tvalue;
            dict.TryGetValue(tkey, out tvalue);
            return tvalue;
        }

        /// <summary>
        /// 增加可重复覆盖字典数据
        /// </summary>
        /// <typeparam name="Tkey"></typeparam>
        /// <typeparam name="Tvalue"></typeparam>
        /// <param name="dict"></param>
        /// <param name="tkey"></param>
        /// <param name="tvalue"></param>
        public static void AddData<Tkey, Tvalue>(this Dictionary<Tkey, Tvalue> dict, Tkey tkey, Tvalue tvalue)
        {
            if (dict.ContainsKey(tkey))
            {
                dict[tkey] = tvalue;
            }
            else
            {
                dict.Add(tkey, tvalue);
            }
        }
    }
}
